<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var removeDuplicates = function (nums) {
      const n = nums.length;
      if (n <= 2) {
        return n;
      }
      let slow = 2, fast = 2;
      while (fast < n) {
        if (nums[slow - 2] != nums[fast]) {
          nums[slow] = nums[fast];
          ++slow;
        }
        ++fast;
      }
      return slow;
    };
    console.log(removeDuplicates(nums = [1, 1, 1, 2, 2, 3]))
  </script>
</body>

</html>